/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package maping;

/**
 *
 * @author Jhon7
 * Acuerdese q toca utilizar matrices y son simplemente multiplicacion
 * no creo q se necesiten mas operaciones...
 */
public class Our2DTransform {
    private static final int _ = -1;    
    private static OurMatrix beginPointMatrix =     new OurMatrix(new double[][]{{_},{_},{1}});    
    
    private static OurMatrix translateMatrix =      new OurMatrix(new double[][]{   {1,0,_},
                                                                                    {0,1,_},
                                                                                    {0,0,1}});    
    
    private static OurMatrix scaleMatrix =          new OurMatrix(new double[][]{   {_,0,0},
                                                                                    {0,_,0},
                                                                                    {0,0,1}});    
    
    private static OurMatrix rotateMatrix =         new OurMatrix(new double[][]{   {_,_,0},
                                                                                    {_,_,0},
                                                                                    {0,0,1}});

    public static OurPoint trasladarPoint(int x, int y, int dx,int dy){
        beginPointMatrix.set(0, 0, x);
        beginPointMatrix.set(1, 0, y);        
        translateMatrix.set(0, 2, dx);
        translateMatrix.set(1, 2, dy);        
        OurMatrix Pp = translateMatrix.product(beginPointMatrix);        
        return new OurPoint(Pp.getRoundedValue(0, 0),Pp.getRoundedValue(1, 0));
    }
    //Ángulo en radianes
    public static OurPoint rotarPoint(int x, int y, float angle){
        beginPointMatrix.set(0, 0, x);
        beginPointMatrix.set(1, 0, y);        
        double cos = Math.cos(angle);
        double sen = Math.sin(angle);        
        rotateMatrix.set(0, 0, cos);
        rotateMatrix.set(0, 1, -sen);
        rotateMatrix.set(1, 0, sen);
        rotateMatrix.set(1, 1, cos);
        OurMatrix Pp = rotateMatrix.product(beginPointMatrix);        
        return new OurPoint(Pp.getRoundedValue(0, 0),Pp.getRoundedValue(1, 0));
    }

    public static OurPoint escalarPoint(int x, int y, float sx,float sy){
        beginPointMatrix.set(0, 0, x);
        beginPointMatrix.set(1, 0, y);        
        scaleMatrix.set(0, 0, sx);
        scaleMatrix.set(1, 1, sy);        
        OurMatrix Pp = scaleMatrix.product(beginPointMatrix);        
        return new OurPoint(Pp.getRoundedValue(0, 0),Pp.getRoundedValue(1, 0));                
    }
}
